<template>
  <div>
    <c-title :text="text"></c-title>
    <div class="owner-apply-for">
      <template v-if="apply_flag == 0">
        <van-cell-group>
          <!-- <van-field label="APPID" required v-model="form.appid" placeholder="请输入用户名" /> -->
          <van-field label="商家账号" required v-model="form.account" placeholder="请输入商家账号" />
          <van-field label="商家密码" required v-model="form.pwd" placeholder="请输入商家密码" />
        </van-cell-group>
        <div class="btn">
          <van-button v-if="form.appid" color="#FE5E56" block round @click="submit">修改申请</van-button>
          <van-button v-else color="#FE5E56" block round @click="submit">申请机主</van-button>
        </div>
      </template>
      <template v-else>
        <div style="padding: 1rem 0.8125rem; text-align: left;">
          <!-- <div>
            <div>APPID</div>
            <div class="message">{{form.appid}}</div>
          </div> -->
          <div style="margin-top: 46px; margin-bottom: 44px;">
            <div>商家账号</div>
            <div class="message">{{form.account}}</div>
          </div>
          <div>
            <div>商家密码</div>
            <div class="message">{{form.pwd}}</div>
          </div>
        </div>

      </template>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      text: '',
      form: {
        appid: "",
        account: "",
        pwd: "",
      },
      apply_flag: 0
    };
  },
  activated() {
    this.apply_flag = this.$route.params.apply_flag;
    if(this.$route.params.apply_flag){
      this.text='机主信息';
    }else{
      this.text='机主申请';
    }
    this.form = {
      // appid: "",
      account: "",
      pwd: "",
    };
    this.getData();
  },
  methods: {
    getData() {
      $http.get('plugin.water-machine.frontend.business.merchant-audit.index').then(res => {
        if (res.result) {
          let data = res.data;
          if (data.status == 0 || data.status == 1) {
            // this.form.appid = data.appid;
            this.form.account = data.account;
            this.form.pwd = data.password;
          }
        } else {
          this.$toast(res.msg);
        }
      })
    },
    submit() {
      $http.post('plugin.water-machine.frontend.business.merchant-audit.apply', {
        account: this.form.account,
        // appid: this.form.appid,
        password: this.form.pwd
      }).then(res => {
        if (res.result) {
          this.$router.push(this.fun.getUrl('water_machine_business'))
        }
        this.$toast(res.msg);
      })
    },

  }
};
</script>

<style scoped lang="scss">
.owner-apply-for {
  position: relative;
  min-height: calc(100vh - 40px);
  background: #fff;

  .btn {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    margin: 0.9375rem 1.7188rem;
  }
}

.owner-apply-for .message {
  color: #7e7e7e;
  font-size: 0.8125rem;
}
</style>
